package com.ruoyi.web.controller.zc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zc.domain.ZcUserGrade;
import com.ruoyi.zc.domain.vo.ZcGradeUserVO;
import com.ruoyi.zc.service.IZcUserGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author xuwendi
 * @date 2023-03-19
 */
@RestController
@RequestMapping("/zc/userGrade")
public class ZcUserGradeController extends BaseController
{
    @Autowired
    private IZcUserGradeService zcUserGradeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcUserGrade zcUserGrade)
    {
        startPage();
        List<ZcUserGrade> list = zcUserGradeService.selectZcUserGradeList(zcUserGrade);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcUserGrade zcUserGrade)
    {
        List<ZcUserGrade> list = zcUserGradeService.selectZcUserGradeList(zcUserGrade);
        ExcelUtil<ZcUserGrade> util = new ExcelUtil<ZcUserGrade>(ZcUserGrade.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(zcUserGradeService.selectZcUserGradeByUserId(userId));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('zc:grade:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcUserGrade zcUserGrade)
    {
        return toAjax(zcUserGradeService.insertZcUserGrade(zcUserGrade));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcUserGrade zcUserGrade)
    {
        return toAjax(zcUserGradeService.updateZcUserGrade(zcUserGrade));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(zcUserGradeService.deleteZcUserGradeByUserIds(userIds));
    }

    @Log(title = "获取用户综测列表")
    @PostMapping("/userGradeList")
    public AjaxResult getZcUserGradeList(){
        List<ZcGradeUserVO> zcUserGradeList = zcUserGradeService.getZcUserGradeList();
        return success(zcUserGradeList);
    }

    @Log(title = "获取用户综测列表")
    @PostMapping("/isGrade/{userId}")
    public AjaxResult isGrade(@PathVariable long userId){
        ZcUserGrade zcUserGrade = zcUserGradeService.selectZcUserGradeByUserId(userId);
        return success(zcUserGrade);
    }


    @Log(title = "根据部门获取用户综测列表")
    @PostMapping("/userGradeList/{deptId}")
    public AjaxResult getZcUserGradeListByDept(@PathVariable long deptId){
        List<ZcGradeUserVO> zcUserGradeList = zcUserGradeService.getZcUserGradeListByDept(deptId);
        return success(zcUserGradeList);
    }

    @Log(title = "获取所有用户综测列表")
    @PostMapping("/userGradeListAll")
    public AjaxResult getZcUserGradeListAll(){
        List<ZcGradeUserVO> zcUserGradeListAll = zcUserGradeService.getZcUserGradeListAll();
        return success(zcUserGradeListAll);
    }

}
